<template>
    <layout>
        <el-page-header @back="$router.back()" :content = this.content></el-page-header>
        <el-form label-width="80px">
            <el-form-item label="分类名称">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save">立即创建</el-button>
            </el-form-item>
        </el-form>
    </layout>
</template>

<script>
export default {
    data() {
        return {
            form: {
                name:''
            },
            content:''
        }
    },
    created() {
        if(this.$route.params.id){
            this.$http.get(`cate/get?id=${this.$route.params.id}`).then(res => {
                if(res.errcode == 0){
                this.form = res.data
                }
            })
            this.content = '编辑分类页面'

        } else{
            this.content = "新增分类页面"
        }
    },
    methods: {
        save() {
            if(this.$route.params.id) {
                this.$http.post('/cate/update',this.form).then(res => {
                    if(res.errcode == 0){
                        this.$router.back()
                    }
                })
            }else{
                this.$http.post('/cate/insert',this.form).then(res => {
                    if(res.errcode == 0){
                        this.$router.back()
                    }
                })
            }

        }
    }
}
</script>
<style>
.el-page-header{
    margin-bottom: 25px;
    margin-top: 5px;
}
</style>>
